#include<bits/stdc++.h>
using namespace std;

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    for (int i = 0; i < m; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
 
    int l = 0, r = m - 1;
    for (int i = 0; i < n; i += 2) {
        for (int j = 0; j < 6; j++) {
            cout << (j % 2 == 0 ? a[l] : a[r]) << " \n"[j == 5];
        }
        if (i + 1 < n) {
            for (int j = 0; j < 6; j++) {
                cout << (j % 2 == 1 ? a[l] : a[r]) << " \n"[j == 5];
            }
        }
        l++, r--;
    }
}

int main(){
	int t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}
